package service

import (
	"fmt"
	"goapp-web-server/app/models"
	"goapp-web-server/app/utils/orm"
)

type CmsCommentService interface {
	GetAll() ([]models.CmsComment, error)
	GetByID(id int64) models.CmsComment
}

func NewCommentService() CmsCommentService {
	return new(commentService)
}

type commentService struct {
}

// comment list
func (s *commentService) GetAll() ([]models.CmsComment, error) {
	engine := orm.Engine
	list := make([]models.CmsComment, 0)
	err := engine.Table("cms_comment").
		Select(`cms_comment.*`).
		Where("cms_comment.deleted_at is NULL").
		Limit(10, 0).
		Find(&list)
	if err != nil {
		fmt.Println("error:", err)
		return nil, err
	}
	return list, nil
}

// get comment by id
func (s *commentService) GetByID(id int64) models.CmsComment {
	comment := models.CmsComment{}
	fmt.Println(comment.Content)
	return comment
}
